package dao

import "adam2/internal/model"

type Real9OptimizeStockTransactionRecordDao interface {
	// 根据账户名，查询正在持仓的股票
	FindByAccountNameAndSellNull(accountName string) model.Real9OptimizeStockTransactionRecordArray

	// 根据账户名和日期，查询当天卖出的股票
	FindByAccountNameAndDateAndSellNotNull(accountName string, date string) model.Real9OptimizeStockTransactionRecordArray

	// 查询某个优化账户之前卖出失败的股票
	FindOptimizeResolveFailSellByAccountName(accountName string) model.Real9OptimizeStockTransactionRecordArray

	// 更新（卖出之前卖出失败的、退市卖出）
	UpdateWhenSell(everyDate string, stockTransactionDataAll model.StockTransactionDataAll, real9OptimizeStockTransactionRecord model.Real9OptimizeStockTransactionRecord)

	// 查询某个账号是否有退市的股票
	FindDelistByLastTransactionDateAndAccountName(lastTransactionDate string, accountName string) model.Real9OptimizeStockTransactionRecordArray

	// 通过id，更新fail_sell_reason字段
	UpdateFailSellReasonById(id int, failSellReason int)

	// 更新（卖出时）
	UpdateWhenOptimizeSell(real9QuantStockTransactionRecord model.Real9QuantStockTransactionRecord)

	// 插入记录
	Insert(accountName string, stockCode string, everyDate string, openPrice float64, amount int,
		registrationFeeWhenBuy float64, commissionWhenBuy float64)

	// 根据账号、日期，查询卖出日期为空的记录，并按照总市值降序排列
	FindByAccountNameAndDateAndSellDateNullOrderByTotalMarketValueDesc(accountName string, everyDate string) model.Real9OptimizeStockTransactionRecordArray

	// 根据账号、日期，查询卖出日期为空的记录，并且不在real9_o_stock_transact_record表中，并按照总市值降序排列（注意不能是最后一个交易日）
	FindByAccountNameAndDateAndSellDateNullAndNotInReal9OptimizeStockTransactionRecordOrderByTotalMarketValueDesc(accountName string, everyDate string) model.Real9OptimizeStockTransactionRecordArray

	// 更新（减仓时）
	UpdateWhenOptimizeSell_underweight(everyDate string, stockTransactionDataAll model.StockTransactionDataAll, real9OptimizeStockTransactionRecord model.Real9OptimizeStockTransactionRecord)

	// 根据buy_date，删除sell_date为空的记录
	DeleteBySellDateNullAndBuyDate(date string)

	// 根据sell_date，将sell_date、sell_price、sell_amount、profit_and_loss、profit_and_loss_rate、stamp_duty、registration_fee_when_sell、commission_when_sell字段改为null
	UpdateNullBySellDate(date string)

	// 根据accountName和stockCode，查询sell_date为空的那一条记录
	FindByAccountNameAndStockCodeAndSellDateNull(accountName string, stockCode string) model.Real9OptimizeStockTransactionRecord
}
